package cn.kys.common.utils;

import org.geotools.geojson.geom.GeometryJSON;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

import java.io.IOException;
import java.io.StringWriter;

public class Utils {

	/**
	 * 
	 * @param input
	 * @return boolean
	 */
	public static boolean isEmpty(String input) {
		if (input == null || "".equals(input))
			return true;

		for (int i = 0; i < input.length(); i++) {
			char c = input.charAt(i);
			if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
				return false;
			}
		}
		return true;
	}

	public static String convertWKTtoGeoJSON(String wkt) throws ParseException, IOException {
		// 使用 JTS 库解析 WKT
		WKTReader wktReader = new WKTReader();
		Geometry geometry = wktReader.read(wkt);
		// 使用 GeometryJSON 将 Geometry 转换为 GeoJSON
		GeometryJSON geometryJSON = new GeometryJSON(12);
		StringWriter writer = new StringWriter();
		geometryJSON.write(geometry, writer);
		return writer.toString();
	}
}
